package com.pacy.pacybaseproject.viewmodels;

import android.app.Application;
import android.os.Bundle;
import android.view.View;


import com.baidu.location.LocationClient;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.activitys.BusMapActivity;
import com.pacy.pacybaseproject.activitys.MsgDetailActivity;
import com.pacy.pacybaseproject.activitys.MsgListActivity;
import com.pacy.pacybaseproject.activitys.RedempPointsActivity;
import com.pacy.pacybaseproject.activitys.RoutingActivity;
import com.pacy.pacybaseproject.activitys.RoutingSearchActivity;
import com.pacy.pacybaseproject.activitys.TravelActivity;
import com.pacy.pacybaseproject.adapters.HomeActivityAdapter;
import com.pacy.pacybaseproject.adapters.HomeMenuAdapter;
import com.pacy.pacybaseproject.adapters.HomeMsgAdapter;
import com.pacy.pacybaseproject.beans.HomeMsgBean;
import com.pacy.pacybaseproject.beans.MenuBean;
import com.pacy.pacybaseproject.events.MainTabEvent;
import com.pacy.pacybaseproject.utils.Constants;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.annotations.NonNull;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;

/**
 * @author PACY
 * @date 2023/12/20
 * description:
 */
public class HomeViewModel extends BaseViewModel {
    public HomeMenuAdapter menuAdapter;
    public HomeMsgAdapter msgAdapter;
    public HomeActivityAdapter activityAdapter;

    //当前城市
    public SingleLiveEvent<String> cityName=new SingleLiveEvent<>("未知");
    //当前城市
    public SingleLiveEvent<Boolean> showCity=new SingleLiveEvent<>(false);

    public HomeViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    protected void init() {
        super.init();
        initAdapter();
    }

    private void initAdapter(){
        menuAdapter=new HomeMenuAdapter();
        List<MenuBean> datas=new ArrayList<>();
        datas.add(new MenuBean("公交", R.drawable.delete_menu_gongjiao_home));
        datas.add(new MenuBean("打车", R.drawable.delete_menu_chuzuche_home));
        datas.add(new MenuBean("路况", R.drawable.delete_menu_sslk_home));
        datas.add(new MenuBean("积分", R.drawable.delete_menu_jfsc_home));
        datas.add(new MenuBean("更多", R.drawable.delete_menu_more_home));

//        datas.add(new MenuBean("步行", R.drawable.delete_menu_buxing));
//        datas.add(new MenuBean("骑行", R.drawable.delete_menu_qixing));
//        datas.add(new MenuBean("定制", R.drawable.delete_menu_dzgj));
//        datas.add(new MenuBean("自驾", R.drawable.delete_menu_zijia));
//        datas.add(new MenuBean("资讯", R.drawable.delete_menu_cxzx));

        menuAdapter.setNewInstance(datas);
        menuAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter<?, ?> adapter, View view, int position) {
                menuAdapter.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(BaseQuickAdapter<?, ?> adapter, View view, int position) {
//                        startActivity(RoutingSearchActivity.class);
                        Bundle bundle=new Bundle();
                        switch (position){
                            case 0:
                                bundle.putInt("initTabPosition",1);
                                startActivity(TravelActivity.class,bundle);
                                break;
                            case 1:
                                bundle.putInt("initTabPosition",2);
                                startActivity(TravelActivity.class,bundle);
                                break;
                            case 3:
                                EventBus.getDefault().post(new MainTabEvent(3));
                                break;
                            case 4:
                                EventBus.getDefault().post(new MainTabEvent(1));
                                break;
                        }
                    }
                });
            }
        });

        msgAdapter=new HomeMsgAdapter();
        List<HomeMsgBean> msgBeans=new ArrayList<>();
        msgBeans.add(new HomeMsgBean(0,"关于市区公交8路优化调整的公告","2024-01-04"));
        msgBeans.add(new HomeMsgBean(1,"关于市区公交部分线路恢复原线路运行的公告","2023-12-08"));
        msgAdapter.setNewInstance(msgBeans);

        msgAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter<?, ?> adapter, View view, int position) {
                Bundle bundle=new Bundle();
                bundle.putInt("position",position);
                bundle.putString("title",msgAdapter.getData().get(position).getContent());
                bundle.putString("time",msgAdapter.getData().get(position).getTime());
                startActivity(MsgDetailActivity.class,bundle);
            }
        });

        activityAdapter=new HomeActivityAdapter();
        activityAdapter.setNewInstance(Constants.getTestData(3));
    }

    /**
     * 去积分页面
     */
    public BindingCommand toIntegralPage=new BindingCommand(() -> {
        EventBus.getDefault().post(new MainTabEvent(3));
    });

    /**
     * 去更多消息
     */
    public BindingCommand toMsgListPage=new BindingCommand(() -> {
        startActivity(MsgListActivity.class);
    });


    /**
     * 去消息详情
     */
    public BindingCommand toMsgPage=new BindingCommand(() -> startActivity(MsgDetailActivity.class));

    /**
     * 去路线规划 startActivity(RoutingSearchActivity.class))
     */
    public BindingCommand toRoutingPage=new BindingCommand(() -> startActivity(TravelActivity.class));


}
